import { request } from '@/network/index'
// 商品分类数据列表
export function getCateData(config) {
  return request(
    {
      url: 'categories',
      method: 'get',
      params: {
        type: config.type,
        pagenum: config.pagenum,
        pagesize: config.pagesize
      }
    }
  )
}
// 获取父级分类数据列表
export function getParentCateData() {
  return request(
    {
      url: 'categories',
      method: 'get',
      params: {
        type: 2
      }
    }
  )
}
// 添加分类
export function addCate(config) {
  return request(
    {
      url: 'categories',
      method: 'post',
      data: {
        cat_pid: config.cat_pid,
        cat_name: config.cat_name,
        cat_level: config.cat_level
      }
    }
  )
}

// 获取所有分类数据
export function allCateList() {
  return request(
    {
      url: 'categories',
      method: 'get'
    }
  )
}
// 获取动态或静态参数列表
export function getAttributes(id, sel) {
  return request(
    {
      url: `categories/${id}/attributes`,
      method: 'get',
      params: {
        sel: sel
      }
    }
  )
}

// 添加动态参数或者静态属性
export function addParamOrAttr(id, attrName, attrSel) {
  return request(
    {
      url: `categories/${id}/attributes`,
      method: 'post',
      data: {
        attr_name: attrName,
        attr_sel: attrSel
      }
    }
  )
}

// 根据 ID 查询参数
export function selectParamById(id, attrId, attrSel) {
  return request(
    {
      url: `categories/${id}/attributes/${attrId}`,
      method: 'get',
      params: {
        attr_sel: attrSel
      }
    }
  )
}

// 编辑提交参数
export function editConfirm(id, attrId, attrName, attrSel) {
  return request(
    {
      url: `categories/${id}/attributes/${attrId}`,
      method: 'put',
      data: {
        attr_name: attrName,
        attr_sel: attrSel
      }
    }
  )
}

// 删除参数
export function deleteParam(id, attrId) {
  return request(
    {
      url: `categories/${id}/attributes/${attrId}`,
      method: 'delete'
    }
  )
}

// 添加tag标签
export function addTag(id, attrId, attrName, attrSel, attrVals) {
  return request(
    {
      url: `categories/${id}/attributes/${attrId}`,
      method: 'put',
      data: {
        attr_name: attrName,
        attr_sel: attrSel,
        attr_vals: attrVals
      }
    }
  )
}

// 获取商品列表数据
export function getGoodsList(config) {
  return request(
    {
      url: 'goods',
      method: 'get',
      params: {
        query: config.query,
        pagenum: config.pagenum,
        pagesize: config.pagesize
      }
    }
  )
}

// 删除商品
export function deleteGoods(id) {
  return request(
    {
      url: `goods/${id}`,
      method: 'delete'
    }
  )
}

// 添加商品
export function addGood(config) {
  return request(
    {
      url: 'goods',
      method: 'post',
      data: {
        goods_name: config.goods_name,
        goods_cat: config.goods_cat,
        goods_price: config.goods_price,
        goods_number: config.goods_number,
        goods_weight: config.goods_weight,
        goods_introduce: config.goods_introduce,
        pics: config.pics,
        attrs: config.attrs
      }
    }
  )
}
